<template>
  <div>
    <el-container>
      <el-header>
        <div id="logoname">校园疫情防控管理系统</div>
        <div id="setting">
          <span>欢迎您，{{ username }}</span>
          <el-dropdown>
            <i
              class="el-icon-setting"
              style="margin-left: 15px; color: white"
            ></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="personalinformationform = true"
                >个人信息</el-dropdown-item
              >
              <el-dropdown-item @click.native="dialogFormVisible = true"
                >更改密码</el-dropdown-item
              >
              <el-dropdown-item>邮箱设置</el-dropdown-item>
              <el-dropdown-item @click.native="pushLogin"
                >退出登录</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
          <el-form :model="form">
            <el-form-item label="旧密码" :label-width="formLabelWidth">
              <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="新密码" :label-width="formLabelWidth">
              <el-input v-model="form.name1" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="确认密码" :label-width="formLabelWidth">
              <el-input v-model="form.name2" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="open()">确 定</el-button>
          </div>
        </el-dialog>
        <el-dialog title="个人信息" :visible.sync="personalinformationform">
          <el-form :model="form" class="personalinformationform">
            <el-form-item label="账号" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name3"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="姓名" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name4"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="籍贯" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name5"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="年龄" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name6"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="性别" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name7"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="班级" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name8"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="身份" :label-width="formLabelWidth">
              <el-input
                v-model="form1.name9"
                disabled
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-form>

          <div slot="footer" class="dialog-footer">
            <!-- <el-button @click="personalinformationform = false"
              >取 消</el-button
            > -->
            <el-button type="primary" @click="personalinformationform = false"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </el-header>
      <el-container id="content">
        <el-aside width="200px">
          <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
          >
            <el-menu-item index="1" @click="goTo('index')">
              <i class="el-icon-location"></i>
              <span slot="title">首页</span>
            </el-menu-item>
            <el-menu-item index="2" @click="goTo('health')">
              <i class="el-icon-menu"></i>
              <span slot="title">填报信息</span>
            </el-menu-item>
            <el-menu-item index="3" @click="goTo('askforleave')">
              <i class="el-icon-document"></i>
              <span slot="title">请假申请</span>
            </el-menu-item>
            <el-menu-item index="4" @click="goTo('message')">
              <i class="el-icon-setting"></i>
              <span slot="title">通知消息</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  created: function () {
    this.getIndex();
  },
  methods: {
    goTo(tmp) {
      console.log(tmp);
      this.$router.push(tmp);
    },
    pushLogin() {
      this.$router.push("/login");
    },
    getIndex() {
      this.$api({
        url: "/index/info",
        method: "post",
        data: { count: window.localStorage.getItem("username") },
        success: (data) => {
          console.log(data[0]);
          this.username = data[0].name;
          this.form1.name3 = data[0].count;
          this.form1.name4 = data[0].name;
          this.form1.name5 = data[0].address;
          this.form1.name6 = data[0].age;
          this.form1.name7 = data[0].sex;
          this.form1.name8 = data[0].class;
          if (data[0].role == 1) {
            this.form1.name9 = "学生";
          } else {
            this.form1.name9 = "教师";
          }
        },
      });
    },
    open() {
      if (!this.form.name) {
        alert("旧密码不能为空！");
      } else if (!this.form.name1) {
        alert("新密码不能为空！");
      } else if (!this.form.name2) {
        alert("确认密码不能为空！");
      } else {
        if (this.form.name1 == this.form.name2) {
          this.$api({
            url: "/index/password",
            method: "post",
            data: {
              count: window.localStorage.getItem("username"),
              oldpassword: this.form.name,
              newpassword: this.form.name1,
            },
            success: (data) => {
              alert(data);
              (this.form.name = ""),
                (this.form.name1 = ""),
                (this.form.name2 = "");
              this.dialogFormVisible = false;
            },
          });
        } else {
          alert("两次密码不一致！");
        }
      }
    },
  },
  data() {
    return {
      username: "",
      dialogFormVisible: false,
      personalinformationform: false,
      form: {
        name: "",
        name1: "",
        name2: "",
      },
      form1: {
        name3: "",
        name4: "",
        name5: "",
        name6: "",
        name7: "",
        name8: "",
        name9: "",
      },
      formLabelWidth: "120px",
    };
  },
};
</script>



<style lang="scss"  >
body {
  padding: 0;
  margin: 0;
}
#content {
  height: 876px;
}
a {
  text-decoration: none;
}
.el-header {
  background-color: rgb(118, 204, 164);
  color: rgb(255, 255, 255);
  // text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  #logoname {
    margin-left: 100px;
    color: #ffffff;
    font-size: 20px;
    letter-spacing: 4px;
  }
  #setting {
    margin-right: 100px;
  }
}
.el-menu-item {
  width: 200px;
}
.el-aside {
  background-color: #545c64;
  line-height: 200px;
}

// .el-main {
//   color: #333;
//   text-align: center;
//   line-height: 160px;
// }

body > .el-container {
  margin-bottom: 40px;
}
</style>